<template>
  <div class="globalzj grayback">
    <van-nav-bar title="支付" left-arrow @click-left="onClickLeft" />
    <div class="jtlist">
      <div>图文问诊:{{ form.actualPayment }}</div>
      <van-cell title="优惠券" :value="form.couponDeduction"></van-cell>
      <van-cell title="积分抵扣" :value="form.pointDeduction"></van-cell>
      <van-cell title="实付款" :value="form.payment"></van-cell>
      <van-cell title="患者信息" :value="form1.name"></van-cell>
      <van-cell title="病情描述" :value="form2.remark"></van-cell>
      <van-submit-bar
        :price="actualPayment"
        button-text="提交订单"
        @submit="onSubmit"
      />
    </div>
  </div>
</template>
<script>
import service from "../request";
export default {
  data() {
    return {
      form: {},
      form1: {},
      form2: {},
      actualPayment: 0,
    };
  },
  mounted() {
    if (window.localStorage.getItem("form")) {
      this.form2 = JSON.parse(window.localStorage.getItem("form"));
    }
    this.getzf();
    this.getinfo();
  },
  methods: {
    async onSubmit() {
      const res1 = await service.post("/patient/consult/order", {
        consultFlag: 1,
        couponId: null,
        depId: window.localStorage.getItem("jsid"),
        illnessDesc: "12",
        illnessTime: 2,
        illnessType: 1,
        patientId: this.form1.id,
        pictures: [],
        type: 2,
      });
      console.log(res1);
let orderId=res1.data.id
      const res = await service.post("/patient/consult/pay", {
        paymentMethod: 1,
        orderId:orderId,
        payCallback:"http://192.168.1.140:8081/#/indexcopy"
      });
      console.log(res)
      window.location.href=res.data.payUrl
    },
    async getinfo() {
      const res = await service.get(
        `/patient/info/${this.$route.query.id}`,
        {}
      );
      console.log(res);
      this.form1 = res.data;
    },
    async getzf() {
      const res = await service.get("/patient/consult/order/pre", {
        params: {
          type: 2,
          illnessType: 1,
        },
      });
      console.log(res);
      this.form = res.data;
      this.actualPayment = this.form.actualPayment * 100;
      console.log(this.actualPayment);
    },
    onClickLeft() {
      this.$router.go(-1);
    },
  },
};
</script>
<style scoped>
.jtlist {
  width: 100%;
  height: calc(100% - 46px);
  overflow: auto;
  padding: 15px;
  box-sizing: border-box;
}
</style>